#include "btform.h"
#include "ui_btform.h"

BtForm::BtForm(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::BtForm)
{
    ui->setupUi(this);

    //设置文本格式
    QFont font;
    font.setFamily("Microsoft YaHei"); // 字体名（可换成“微软雅黑”、“SimSun”等）
    font.setPixelSize(13);             // 字体大小（像素）
    font.setBold(false);                // 是否加粗
    ui->btText->setFont(font);


    //默认隐藏动画
    hideAnimal();

    //设置line1动画效果
    line1Animal = new QPropertyAnimation(ui->line1,"geometry",this);
    line1Animal->setDuration(1300);
    line1Animal->setKeyValueAt(0,QRect(5,15,2,0));
    line1Animal->setKeyValueAt(0.5,QRect(5,0,2,15));
    line1Animal->setKeyValueAt(1,QRect(5,15,2,0));
    line1Animal->setLoopCount(-1);
    line1Animal->start();
    //设置line2动画效果
    line2Animal = new QPropertyAnimation(ui->line2,"geometry",this);
    line2Animal->setDuration(1450);
    line2Animal->setKeyValueAt(0,QRect(10,15,2,0));
    line2Animal->setKeyValueAt(0.5,QRect(10,0,2,15));
    line2Animal->setKeyValueAt(1,QRect(10,15,2,0));
    line2Animal->setLoopCount(-1);
    line2Animal->start();
    //设置line3动画效果
    line3Animal = new QPropertyAnimation(ui->line3,"geometry",this);
    line3Animal->setDuration(1600);
    line3Animal->setKeyValueAt(0,QRect(15,15,2,0));
    line3Animal->setKeyValueAt(0.5,QRect(15,0,2,15));
    line3Animal->setKeyValueAt(1,QRect(15,15,2,0));
    line3Animal->setLoopCount(-1);
    line3Animal->start();
    //设置line4动画效果
    line4Animal = new QPropertyAnimation(ui->line4,"geometry",this);
    line4Animal->setDuration(1750);
    line4Animal->setKeyValueAt(0,QRect(20,15,2,0));
    line4Animal->setKeyValueAt(0.5,QRect(20,0,2,15));
    line4Animal->setKeyValueAt(1,QRect(20,15,2,0));
    line4Animal->setLoopCount(-1);
    line4Animal->start();
}

BtForm::~BtForm()
{
    delete ui;
}

void BtForm::setIconAndTextAndPage(const QString &icon, const QString &text,const int pageId)
{
    //设置btForm的图标和文本
    QPixmap pixmap(icon);
    pixmap = pixmap.scaled(20, 20,Qt::KeepAspectRatio);
    ui->btIcon->setPixmap(pixmap);
    ui->btText->setText(text);
    //关联按键与页面
    this->pageId = pageId;
}

int BtForm::getPageId() const
{
    return this->pageId;
}


void BtForm::clearBackground() const
{
    ui->btStyle->setStyleSheet("#btStyle:hover{background-color:#D8D8D8;}");
}

void BtForm::setBackground() const
{
    //改变颜色
    ui->btStyle->setStyleSheet("#btStyle{background-color:rgb(30,206,154);}");
}

void BtForm::showAnimal() const
{
    ui->lineBox->setVisible(true);
}

void BtForm::hideAnimal() const
{
    ui->lineBox->setVisible(false);
}

void BtForm::mousePressEvent(QMouseEvent *event)
{
    if(event->buttons() == Qt::LeftButton){
        //切换stackedWidget页面
        emit btFormClick(this->pageId);
        setBackground();
    }
    QWidget::mousePressEvent(event);
}
